package com.atguigu.greedy;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

public class GreedyAlgorithm1 {
    public static void main(String[] args) 
    {
        HashMap<String,HashSet<String>> broadcasts=new HashMap<String,HashSet<String>>();
         
        broadcasts.put("k1", new HashSet<String>(){{add("北京");add("上海");add("天津");}});
        broadcasts.put("k2", new HashSet<String>(){{add("广州");add("深圳");}});
        broadcasts.put("k3",new HashSet<String>(){{add("成都");add("上海");add("杭州");}});
        broadcasts.put("k4",new HashSet<String>(){{add("上海");add("天津");}});
        broadcasts.put("k5", new HashSet<String>(){{add("杭州");add("大连");}});

        HashSet<String> allAreas=new HashSet<String>(){{add("北京");add("上海");add("天津");add("广州");add("深圳");add("成都");add("杭州");add("大连");}};

        // 被选中的
        ArrayList<String> selects = new ArrayList<String>();

        HashSet<String> tempSet = new HashSet<String>();
       
       
        for(String key : broadcasts.keySet())
        {
          tempSet.clear();
          tempSet.addAll(broadcasts.get(key));
          tempSet.retainAll(allAreas);
          if(tempSet.size() > 0 && broadcasts.containsKey(key)
                      )
           {
                       
                        selects.add(key);
                        allAreas.removeAll(broadcasts.get(key));
                       
            }
             
           
     }

        System.out.println(selects);
    }
}